package IO_.homework;

import java.io.*;
import java.util.Scanner;

/**
 * 进行普通文件的复制
 */
public class test2 {
    public static void main(String[] args) {
        System.out.println("请输入原文件名:");
        Scanner scan=new Scanner(System.in);
        String src=scan.next();
        File file = new File(src);
        if(!file.isFile()){
            System.out.println("输入的文件名有误!!");
            return;
        }
        System.out.println("请输入要复制的文件名:");
        String desc=scan.next();
        File file1 = new File(desc);
        if(file1.getParentFile().isDirectory()){
            System.out.println("要复制的路径有误");
            return;
        }
        try (FileInputStream inputStream = new FileInputStream(file);
             OutputStream outputStream = new FileOutputStream(file1)){
            while(true){
                byte[] buffer=new byte[1024];
                int n=inputStream.read(buffer);
                if(n==-1){
                    break;
                }
                outputStream.write(buffer,0,n);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
